<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Theme_Expansion extends Theme
{
	private $themeName		=	'expansion';
	/*  ==  */
	public $name			= 'Expansion theme';
    public $author			= 'Lee ( trojan_spike )';
    public $author_website	= 'http://phpacademy.org';
    public $website			= 'http://phpacademy.org';
    public $description		= 'A theme I\'m working on that will be getting extras added to it as time goes on. <br /> <span style="color:blue;">CSS3 , HTML5 - Canvas, Twitter bootsrap plus other goodies</span>.';
    public $version			= '1.2';
	public $options;
	
	function __construct()
	{
		if ($this->uri->segment(4) == $this->themeName)
			{
				$this->_theme_widget_areas();
				$this->_theme_navigation_groups();
				$this->_theme_variables();
			}
			
		$this->options = $this->_set_options();
		
	} // __construct()
	
	private function _set_options()
	{
		$this->load->library('files/files');
		$folders = Files::folder_tree();
		if(empty($folders)){
			// create a virtual folder
			Files::create_folder(
			$parent = 0, 
			$name = 'Site Slider Folder', 
			$location = 'local', 
			$remote_container = '');
			$folders[0]['slug']='site-slider-folder';
			}
		/*********************************/
		$options['theme']	= 	array(
				'title'         => 'Color scheme',
				'description'   => 'Choose a color theme for your site, more to be added',
				'default'       => 'site-theme-red',
				'type'          => 'select',
				'options'       => 'site-theme-red=Red|
									site-theme-yellow=Yellow',
				'is_required'   => TRUE
			);
			
		$options['fullFluid']	=	array(
				'title'			=>	'Full fluid layout?',
				'description'	=>	'another description',
				'default'		=>	'container',
				'type'			=>	'radio',
				'options'		=>	'container=No|
									container-fluid=Yes',
				'is_required'	=> 	TRUE
			);
		$options['useTimeAgo'] 	= 	array(
				'title'         => 	'Use timeago on comments?',
				'description'   => 	'Time ago shows how long ago a post was submitted',
				'default'       => 	'yes-time-ago',
				'type'          => 	'radio',
				'options'       => 	'no-time-ago=no|
									yes-time-ago=Yes',
				'is_required'   => TRUE
		);
		$options['followMenu']	=	array(
				'title'			=>	'Let the menu follow users down the page?',
				'description'	=>	'When on , the nav menu will follow dow the side of the page.',
				'default'		=>	'yes-followMenu',
				'type'			=>	'radio',
				'options'		=>	'no-followMenu=No|
									yes-followMenu=Yes',
				'is_required'	=> 	TRUE
			);
			
		$options['ShowBreadcrumbs']=array(
				'title'			=>	'Show bread crumbs?',
				'description'	=>	'Showing breadcrumbs increases rating at google and other search engines',
				'default'		=>	'yes',
				'type'			=>	'radio',
				'options'		=>	'no=No|
									yes=Yes',
				'is_required'	=> 	TRUE
			);	
		$options['ShowSidebar']	=	array(
				'title'			=>	'Show sidebar?',
				'description'	=>	'Would you like to display the sidebar to users?',
				'default'		=>	'span9',
				'type'			=>	'radio',
				'options'		=>	'span12=No|
									span9=Yes',
				'is_required'	=> 	TRUE
			);	
		/*************************************************/		
			
		$options['ShowSlider']	=	array(
				'title'			=>	'Show image slider?',
				'description'	=>	'Would you like to display the website\'s image slider?',
				'default'		=>	'yes',
				'type'			=>	'radio',
				'options'		=>	'no=No|
									yes=Yes',
				'is_required'	=> 	TRUE
			);	
			
		$options['ChoosenSlider']=array(
				'title'			=>	'Which Slider would you like to show?',
				'description'	=>	'Please select a slider , more will be added as time goes on.',
				'default'		=>	'BootstrapCarousel',
				'type'			=>	'select',
				'options'		=>	'BootstrapCarousel=Bootstrap Carousel|
									experimentalCanvasGallery=Experimental Canvas Gallery',
				'is_required'	=> 	TRUE
			);	
		$options['SliderFolder']=	array(
				'title'			=>	'Show images from which folder?',
				'description'	=>	'Shows the images in the website slider',
				'default'		=>	$folders[0]['slug'],
				'type'			=>	'select',
				'options'		=>	substr($this->_to_select_string($folders), 1),
				'is_required'	=> 	TRUE
			);	
		
		
			/*===============*/
		$options['imgBox']		=	array(
				'title'			=>	'Show image box effects?',
				'description'	=>	'Increases size so users can get a better look. ',
				'default'		=>	'yes',
				'type'			=>	'radio',
				'options'		=>	'no=No|
									yes=Yes',
				'is_required'	=> 	TRUE
			);
			
		$options['imgBoxType']	=	array(
				'title'			=>	'Which images box effect?',
				'description'	=>	'More image effect will be added as time goes on.',
				'default'		=>	'lightbox2',
				'type'			=>	'select',
				'options'		=>	'lightbox2=Light box 2|
									simpleHoverShow=Hover and show',
				'is_required'	=> 	TRUE
			);			
			
		return $options;
	} // _set_options()
	
	private function _theme_widget_areas()
	{
		$widget_slugs_installed = array();
		$theme_widgets_needed=array(
		$this->themeName.'-widget-area-footer' 		=> $this->themeName.' Widget Footer',
		$this->themeName.'-widget-area-comments' 	=> $this->themeName.' Widget Comments',
		$this->themeName.'-widget-area-sidebar' 	=> $this->themeName.' Widget Sidbar',
		$this->themeName.'-widget-area-header' 		=> $this->themeName.' Widget Header'
									);
		foreach($this->db->select('slug')->get('widget_areas')->result() as $row)
		{ $widget_slugs_installed[]=$row->slug; }
		
		foreach($theme_widgets_needed as $install_widget_slug => $install_widget_title){
			if(!in_array($install_widget_slug, $widget_slugs_installed)){
				$data = array(
   					'slug' => $install_widget_slug ,
   					'title' => $install_widget_title );
				$this->db->insert('widget_areas', $data); 			
			} // if(!in_array(
		} // foreach($theme
	} // _theme_widget_areas()
	
	private function _theme_navigation_groups()
	{
		$navigation_abbrev_installed = array();
		$theme_navgations_needed=array(
		$this->themeName.'-navigation-area-sidebar' 	=> $this->themeName.' Naviagation Sidebar',
		$this->themeName.'-navigation-area-main-nav' 	=> $this->themeName.' Naviagation Main nav',
		$this->themeName.'-navigation-area-footer1' 	=> $this->themeName.' Naviagation Footer 1',
		$this->themeName.'-navigation-area-footer2' 	=> $this->themeName.' Naviagation Footer 2'
									);
		foreach($this->db->select('abbrev')->get('navigation_groups')->result() as $row)
		{ $navigation_abbrev_installed[]=$row->abbrev; }
		
		foreach($theme_navgations_needed as 
					$install_navgations_slug => $install_navgations_title){
			if(!in_array($install_navgations_slug, $navigation_abbrev_installed)){
				$data = array(
					'title' => $install_navgations_title,
   					'abbrev' => $install_navgations_slug
   					 );
				$this->db->insert('navigation_groups', $data); 
			} // if(!in_array(
		} // foreach($theme
	} // _theme_navigation_areas()
	
	private function _theme_variables()
	{
		$variables_installed = array();
		$variables_needed=array(
		'DevThemeName' 	=> $this->themeName
									);
		foreach($this->db->select('name')->get('variables')->result() as $row)
		{ $variables_installed[]=$row->name; }
		
		foreach($variables_needed as 
					$variables_name => $variables_value){
			if(!in_array($variables_name, $variables_installed)){
				$data = array(
					'name' => $variables_name,
   					'data' => $variables_value
   					 );
				$this->db->insert('variables', $data); 
			} // if(!in_array(
		} // foreach($theme
	} // _theme_variables()
	private function _to_select_string($folders)
	{
		$select = '';
		foreach($folders as $folder)
		{
			$select .= '|'.$folder['slug'].'='.$folder['name'];
		}
		//  return the top most parent folders
		return $select;
	} 
	// _owners_folders()
	
}// Class

/* End of file theme.php */